<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 编写函数maxr(char) 返回字符串char中最长的连续重复字母

比如maxr("mmmiijjjjkkkkkkssptr") 返回"kkkkkk" -->
    <script>
        var str = "mmmiijjjjkkkkkkssptr";
        function maxr(char) {
            var i = 0;
            var j = 1;
            var maxlength = 0;
            var maxchar = "";
            while (i < char.length) {
                if (char.charAt(i) == char.charAt(j)) {
                    j++
                } else {
                    if(j-i > maxlength) {
                        maxlength = j-i;
                        maxchar = char.charAt(i);
                    }
                    i = j;
                    j++;
                }
            }
            return maxchar;
        }
        console.log(maxr(str));
    </script>
</body>
</html>